package com.woniu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
public interface UserMapper extends BaseMapper<User> {
    /*/**
     *@description  根据id查询user  带出部门和角色
     *@params []
     *@return_value com.woniu.entity.User
     *@author hyl
     *@date 2022/8/29
     */
    @Select("select * from user,role,dept where role.role_id=user.role_id and user.dept_id=dept.dept_id and user.user_id=${userId}")
    @Results(id = "userMap", value = {
            @Result(column = "dept_id", property = "dept.deptId"),
            @Result(column = "dept_name", property = "dept.deptName"),
            @Result(column = "dept_status", property = "dept.deptStatus"),
            @Result(column = "dept_manager_id", property = "dept.deptManagerId"),
            @Result(column = "role_id", property = "role.roleId"),
            @Result(column = "role_name", property = "role.roleName"),
            @Result(column = "role_status", property = "role.roleStatus"),
    })
    User getByUserId(Integer userId);

    /*/**
     *@description 根据条件查询所有用户
     *@params [user]
     *@return_value java.util.List<com.woniu.entity.User>
     *@author hyl
     *@date 2022/8/29
     */
    @Select("select * from user,role,dept ${ew.customSqlSegment} and role.role_id=user.role_id and user.dept_id=dept.dept_id")
    @ResultMap("userMap")
    List<User> getByAnyUser(@Param(Constants.WRAPPER) Wrapper<User> wrapper);

    /*/**
     *@description 根据条件查询用户并分页
     *@params [page, wrapper]
     *@return_value java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     *@author hyl
     *@date 2022/8/29
     */
    @Select("select * from user,role,dept ${ew.customSqlSegment} and role.role_id=user.role_id and user.dept_id=dept.dept_id")
    @ResultMap("userMap")
    Page<User> getByAnyUserWithPage(Page<User> page, @Param(Constants.WRAPPER) Wrapper<User> wrapper);

    /*/**
     *@description 根据项目id查询用户
     *@params [proId]
     *@return_value java.util.List<com.woniu.entity.User>
     *@author hyl
     *@date 2022/8/29
     */
    @Select("select * from user,user_mid_pro,dept,role where pro_id = ${proId} and user.user_id = user_mid_pro.user_id and role.role_id=user.role_id and user.dept_id=dept.dept_id")
    @ResultMap("userMap")
    List<User> getUserByProId(Integer proId);
}
